﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Yugi.Client.Card
{
    public class CardManager
    {
        private static Dictionary<int, YBaseCard> Data = new Dictionary<int, YBaseCard>();
        private static Dictionary<YType, int> Statistic = new Dictionary<YType, int>();
        public static int Total;
        public CardManager()
        {

        }
        public static void addCard(YBaseCard card, int id)
        {
            if (Data.ContainsKey(id)) return;
            Data.Add(id, card);
            UpdateStatictic(card.CardType);
            Total++;
        }
        private static void UpdateStatictic(YType t)
        {
            if (Statistic.ContainsKey(t))
            {
                Statistic[t]++;
            }
            else
            {
                Statistic.Add(t, 1);
            }
        }

        public int GetStatistic(YType type)
        {

            return Statistic[type];

        }
        private object GetValue(Func<KeyValuePair<int, YBaseCard>, bool> expression)
        {
            return Data.Where(expression).ToList();
        }
        public List<KeyValuePair<int, YBaseCard>> GetCardByType(YType type)
        {

            List<KeyValuePair<int, YBaseCard>> res = null;
            res = GetValue((KeyValuePair<int, YBaseCard> p) => p.Value.CardType == type) as List<KeyValuePair<int, YBaseCard>>;
            return res;

        }
        public List<int> GetRandom(int count)
        {
            List<int> res = new List<int>();
            Random ran = new Random();
            int total = Data.Count;
            for (int i = 0; i < count; i++)
            {
                res.Add(ran.Next(total-1)+1);
            }

            return res;
        }
        public YBaseCard this[int id]
        {
            get
            {
                return Data[id] as YBaseCard;
            }

        }
    }
}
